#include "qpicturetool.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneContextMenuEvent>
#include <QImage>
#include <QPainter>
#include <QGraphicsItem>

QPictureTool::QPictureTool(QObject *parent)
	: QMyTool(parent)
{

}

QPictureTool::~QPictureTool()
{

}

void QPictureTool::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
	QString fileName=QFileDialog::getOpenFileName(0, tr("Open Image"),"", tr("Images (*.png *.xpm *.jpg)"));
	if (!fileName.isEmpty()) 
	{
		QImage image(fileName);
		if (image.isNull()) 
		{
			QMessageBox::information(0, tr("Image Viewer"),
				tr("Cannot load %1.").arg(fileName));
			return;
		}
		controller->receiveMessage(new NewNodeMessage(
			NewNodeArgs(pictureNode,mouseEvent->scenePos(),fileName)));
		int i=controller->NumberOfObjects()-1;
		Container->AddPixmapItem(i);
	}
}
void QPictureTool::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
}
void QPictureTool::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
}
void QPictureTool::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
}
void QPictureTool::contextMenuEvent(QGraphicsSceneContextMenuEvent * mouseEvent)
{
}